<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Models\GameCodeCacheModel;
class GameCodeController extends HomeController
{
    /**
     * 上传文件解析文件
     */
    public function import(Request $request)
    {
        try{
            $this->validate($request, [
                'apptoken' => 'required',
                'codes' => 'codes'
            ]);
            $codes = $request->input('codes');
            if($codes) {
                $codes = json_decode($codes, true);
                $key = generate_nonce_str();
                GameCodeCacheModel::sadd($key, $codes);
                return response()->json(build_result(["key" => $key]);
            } else {
                return response()->json(build_result('', '20001', ''));
            }
        } catch (\Exception $e) {
            return response()->json(build_result('', '10001', $e->getMessage()));
        }
    }
}
